#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys

execfile(os.path.join(sys.path[0], "framework.py"))

from oriolus.pith.packets.packet import FullName, FullNameParseError
from unittest import TestCase, TestLoader, TextTestRunner

class TestFullname(TestCase):
    def test_1(self):
        fullname1 = FullName("name1", "version1")
        fullname2 = FullName("name1", "version1")
        
        self.assertTrue(fullname1 == fullname2)
        
    def test_2(self):
        fullname1 = FullName("name1", "version1")
        fullname2 = FullName("name1", "version2")
        
        self.assertTrue(fullname1 != fullname2)
        
    def test_3(self):
        fullname1 = FullName("name1", "version1")
        fullname2 = FullName("name2", "version1")
        
        self.assertTrue(fullname1 != fullname2)
        
    def test_4(self):
        fullname1 = FullName("name1", "version1")
        fullname2 = FullName("name2", "version2")
        
        self.assertTrue(fullname1 != fullname2)

    def test_5(self):
        fullname = FullName("name", "")
        
        self.assertEqual("name", fullname.name)
        self.assertEqual("", fullname.version)

    def test_parse_full_name(self):
        full_name_string = "packet-1.2.3.4"
        
        packet_full_name = FullName.parse(full_name_string)
        
        self.assertEqual("packet", packet_full_name.name)
        self.assertEqual("1.2.3.4", packet_full_name.version)
        
    def test_parse_full_name_with_empty_version(self):
        full_name_string = "packet"
        
        self.assertRaises(FullNameParseError, FullName.parse, full_name_string)

if __name__ == "__main__":
    suite = TestLoader().loadTestsFromTestCase(TestFullname)
    TextTestRunner(verbosity=2).run(suite)
    